home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / e / eiffel.lha / flc / source / entity_tree.e < prev    next >
Encoding:
Text File  |  1995-12-27  |  1.4 KB  |  68 lines

  1.  
  2. -> Copyright © 1995, Guichard Damien.
  3.  
  4. -> Trees of Eiffel entities are used whenever possible
  5.  
  6. OPT MODULE
  7. OPT EXPORT
  8.  
  9. MODULE '*treed_entity'
  10. MODULE '*strings'
  11.  
  12. -> Tree of Eiffel entities
  13. OBJECT entity_tree
  14.   cells:PTR TO treed_entity
  15. ENDOBJECT
  16.  
  17. -> Add an entity to the tree
  18. PROC add(e:PTR TO treed_entity) OF entity_tree
  19.   DEF parent:PTR TO treed_entity,cell:PTR TO treed_entity
  20.   cell:=self.cells
  21.   IF cell=NIL
  22.     self.cells:=e
  23.     RETURN
  24.   ENDIF
  25.   WHILE cell
  26.     parent:=cell
  27.     cell:=IF e.int<cell.int THEN cell.left ELSE cell.right
  28.   ENDWHILE
  29.   IF e.int<parent.int
  30.     parent.left:=e
  31.   ELSE
  32.     parent.right:=e
  33.   ENDIF
  34. ENDPROC
  35.  
  36. -> Find an entity in the tree
  37. PROC find(name:PTR TO CHAR) OF entity_tree
  38.   DEF value:LONG,cell:PTR TO treed_entity
  39.   value:=hash(name)
  40.   cell:=self.cells
  41.   LOOP
  42.     IF cell=NIL THEN RETURN NIL
  43.     IF cell.int=value THEN
  44.       IF StrCmp(name,cell.name,ALL) THEN RETURN cell
  45.     cell:=IF value<cell.int THEN cell.left ELSE cell.right
  46.   ENDLOOP
  47. ENDPROC
  48.  
  49. -> Continuation
  50. PROC continu(c:PTR TO treed_entity,name) OF entity_tree
  51.   DEF value:LONG,cell:PTR TO treed_entity
  52.   IF c=NIL THEN RETURN NIL
  53.   value:=hash(name)
  54.   cell:=c.right
  55.   LOOP
  56.     IF cell=NIL THEN RETURN NIL
  57.     IF cell.int=value THEN
  58.       IF StrCmp(name,cell.name,ALL) THEN RETURN cell
  59.     cell:=IF value<cell.int THEN cell.left ELSE cell.right
  60.   ENDLOOP
  61. ENDPROC
  62.  
  63. -> Wipe out.
  64. PROC wipe_out() OF entity_tree
  65.   self.cells:=NIL
  66. ENDPROC
  67.  
  68.